/**
 * 
 */
package com.base_data_handler.function.weather;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.dom4j.CDATA;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.base_data_handler.function.model.AirInfo;
import com.base_data_handler.function.model.AllData;
import com.base_data_handler.function.model.Forcast;
import com.base_data_handler.function.model.Life;
import com.base_data_handler.function.model.Real;
import com.base_data_handler.function.model.Warning;
import com.base_data_handler.utils.DBUtil;
import com.base_data_handler.utils.DataSourceUtils;
import com.base_data_handler.utils.DruidPlugin;

/**
 * @author Administrator
 *
 */
public class RealForcastLifeWarnFromChinaWeather {
//	private	static QueryRunner qr=new QueryRunner(DruidPlugin.getDataSource());
	private	static QueryRunner qr=new QueryRunner(DataSourceUtils.getDatasSource());
	public AllData getAllData(String cityid,String county){
	
		AllData ad=new AllData();
		
		Real real=new Real();
		
		Life lf=new Life();
		
		Forcast fs=new Forcast();
		
		Warning  wr=new Warning();
		
		
		
		Document document;
		InputStream in = null; 
		InputStreamReader r = null;
		try {
			
			   SAXReader xmlReader = new SAXReader(); 
			   xmlReader.setEncoding("gbk");
			   URL geturl=new URL("http://wthrcdn.etouch.cn/WeatherApi?citykey="+cityid);
//			   System.out.println(geturl.openConnection().getContentEncoding());
			    in=new GZIPInputStream(geturl.openStream());
			    r = new InputStreamReader(in,"utf-8");  
			   document = xmlReader.read(r); 
			    Element node = document.getRootElement();
			    
			    //解析实况
			    readReal( cityid, county,ad, real, node);
			    
			    /**
			     * 预报解析
			     */
			    readForcast(ad, fs, node);
			    /**
				  * 生活指数
				  */
			    readLife(ad,lf, node);
				
				/**
				 * 预警解析
				 */
				 readWarn(ad, wr, node);
				
				
			   
			    
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
				try {
					 if(r!=null) r.close();
					 if(in!=null)in.close();
					 
				} catch (IOException e) {
					e.printStackTrace();
				}
	   }
			
		return ad;
	}

	private void readLife(AllData ad,Life lf, Element node) {
		Element zhishus=node.element("zhishus");
		List<Element> zhishu = zhishus.elements();
		 for (int i = 0; i < zhishu.size(); i++) {
			 if(i==0){
				 lf.setL_name_cl(zhishu.get(i).element("name").getText());
				 lf.setL_value_cl(zhishu.get(i).element("value").getText());
				 lf.setL_detail_cl(zhishu.get(i).element("detail").getText());
			 }else if(i==1){
				 lf.setL_name_ssd(zhishu.get(i).element("name").getText());
				 lf.setL_value_ssd(zhishu.get(i).element("value").getText());
				 lf.setL_detail_ssd(zhishu.get(i).element("detail").getText());
			 }else if(i==2){
				 lf.setL_name_cy(zhishu.get(i).element("name").getText());
				 lf.setL_value_cy(zhishu.get(i).element("value").getText());
				 lf.setL_detail_cy(zhishu.get(i).element("detail").getText());
			 }else if(i==3){
				 lf.setL_name_gm(zhishu.get(i).element("name").getText());
				 lf.setL_value_gm(zhishu.get(i).element("value").getText());
				 lf.setL_detail_gm(zhishu.get(i).element("detail").getText());
			 }else if(i==4){
				
				 lf.setL_name_ls(zhishu.get(i).element("name").getText());
				 lf.setL_value_ls(zhishu.get(i).element("value").getText());
				 lf.setL_detail_ls(zhishu.get(i).element("detail").getText());
			 }else if(i==5){
				
				 lf.setL_name_ly(zhishu.get(i).element("name").getText());
				 lf.setL_value_ly(zhishu.get(i).element("value").getText());
				 lf.setL_detail_ly(zhishu.get(i).element("detail").getText());
			 }else if(i==6){
				 lf.setL_name_zwx(zhishu.get(i).element("name").getText());
				 lf.setL_value_zwx(zhishu.get(i).element("value").getText());
				 lf.setL_detail_zwx(zhishu.get(i).element("detail").getText());
			 }else if(i==7){
				 lf.setL_name_xc(zhishu.get(i).element("name").getText());
				 lf.setL_value_xc(zhishu.get(i).element("value").getText());
				 lf.setL_detail_xc(zhishu.get(i).element("detail").getText());
			 }else if(i==8){
				 lf.setL_name_yd(zhishu.get(i).element("name").getText());
				 lf.setL_value_yd(zhishu.get(i).element("value").getText());
				 lf.setL_detail_yd(zhishu.get(i).element("detail").getText());
			 }else if(i==9){
				 lf.setL_name_yh(zhishu.get(i).element("name").getText());
				 lf.setL_value_yh(zhishu.get(i).element("value").getText());
				 lf.setL_detail_yh(zhishu.get(i).element("detail").getText());
			 }else if(i==10){
				 lf.setL_name_ys(zhishu.get(i).element("name").getText());
				 lf.setL_value_ys(zhishu.get(i).element("value").getText());
				 lf.setL_detail_ys(zhishu.get(i).element("detail").getText());
			 }
		 }
		 ad.setLf(lf);
//		 System.out.println(lf.toString());
	}

	private void readWarn(AllData ad, Warning wr, Element node) {
		if(null!=node.element("alarm")){
			wr.setW_form(node.element("alarm").element("cityName").getText());
			wr.setW_title(node.element("alarm").element("alarmText").getText());
			wr.setW_type(node.element("alarm").element("alarmType").getText());
			wr.setW_type_img(1);
			wr.setW_degree(node.element("alarm").element("alarmDegree").getText());
			wr.setW_degree_img(1);
			wr.setW_standard(node.element("alarm").element("standard").getText());
			wr.setW_suggest(node.element("alarm").element("suggest").getText());
			wr.setW_time(node.element("alarm").element("time").getText());
			wr.setW_details(node.element("alarm").element("alarm_details").getText());
		}
		
		
		 ad.setWarning(wr);
//		 System.out.println(wr.toString());
	}

	private void readForcast(AllData ad, Forcast fs, Element node) {
		Element forcasts=node.element("forecast");
		@SuppressWarnings("unchecked")
		List<Element> forcast = forcasts.elements();
		for (int i = 0; i < forcast.size(); i++) {
			if(i==0){
				fs.setF_day_1((int)reGexNum(forcast.get(i).element("date").getText()));
				fs.setF_week_1(getWeek(forcast.get(i).element("date").getText()));
				fs.setF_temp_h1(reGexNum(forcast.get(i).element("high").getText()));
				fs.setF_temp_l1(reGexNum(forcast.get(i).element("low").getText()));
				
				fs.setF_d_1_fl(reGexNum(forcast.get(i).element("day").element("fengli").getText())+"");
				fs.setF_d_1_fx(forcast.get(i).element("day").element("fengxiang").getText());
				fs.setF_d_1_wf(forcast.get(i).element("day").element("type").getText());
//						fs.setF_d_1_wf_img();
//						
				fs.setF_n_1_fl(reGexNum(forcast.get(i).element("night").element("fengli").getText())+"");
				fs.setF_n_1_fx(forcast.get(i).element("night").element("fengxiang").getText());
				fs.setF_n_1_wf(forcast.get(i).element("night").element("type").getText());
//						fs.setF_n_1_wf_img();
				
			}else if(i==1){
				fs.setF_day_2((int)reGexNum(forcast.get(i).element("date").getText()));
				fs.setF_week_2(getWeek(forcast.get(i).element("date").getText()));
				fs.setF_temp_h2(reGexNum(forcast.get(i).element("high").getText()));
				fs.setF_temp_l2(reGexNum(forcast.get(i).element("low").getText()));
				
				fs.setF_d_2_fl(reGexNum(forcast.get(i).element("day").element("fengli").getText())+"");
				fs.setF_d_2_fx(forcast.get(i).element("day").element("fengxiang").getText());
				fs.setF_d_2_wf(forcast.get(i).element("day").element("type").getText());
//						fs.setF_d_2_wf_img();
//						
				fs.setF_n_2_fl(reGexNum(forcast.get(i).element("night").element("fengli").getText())+"");
				fs.setF_n_2_fx(forcast.get(i).element("night").element("fengxiang").getText());
				fs.setF_n_2_wf(forcast.get(i).element("night").element("type").getText());
//						fs.setF_n_2_wf_img();
			}else if(i==2){
				fs.setF_day_3((int)reGexNum(forcast.get(i).element("date").getText()));
				fs.setF_week_3(getWeek(forcast.get(i).element("date").getText()));
				fs.setF_temp_h3(reGexNum(forcast.get(i).element("high").getText()));
				fs.setF_temp_l3(reGexNum(forcast.get(i).element("low").getText()));
				
				fs.setF_d_3_fl(reGexNum(forcast.get(i).element("day").element("fengli").getText())+"");
				fs.setF_d_3_fx(forcast.get(i).element("day").element("fengxiang").getText());
				fs.setF_d_3_wf(forcast.get(i).element("day").element("type").getText());
//						fs.setF_d_3_wf_img();
//						
				fs.setF_n_3_fl(reGexNum(forcast.get(i).element("night").element("fengli").getText())+"");
				fs.setF_n_3_fx(forcast.get(i).element("night").element("fengxiang").getText());
				fs.setF_n_3_wf(forcast.get(i).element("night").element("type").getText());
//						fs.setF_n_1_wf_img();
			}else if(i==3){
				fs.setF_day_4((int)reGexNum(forcast.get(i).element("date").getText()));
				fs.setF_week_4(getWeek(forcast.get(i).element("date").getText()));
				fs.setF_temp_h4(reGexNum(forcast.get(i).element("high").getText()));
				fs.setF_temp_l4(reGexNum(forcast.get(i).element("low").getText()));
				
				fs.setF_d_4_fl(reGexNum(forcast.get(i).element("day").element("fengli").getText())+"");
				fs.setF_d_4_fx(forcast.get(i).element("day").element("fengxiang").getText());
				fs.setF_d_4_wf(forcast.get(i).element("day").element("type").getText());
//						fs.setF_d_4_wf_img();
//						
				fs.setF_n_4_fl(reGexNum(forcast.get(i).element("night").element("fengli").getText())+"");
				fs.setF_n_4_fx(forcast.get(i).element("night").element("fengxiang").getText());
				fs.setF_n_4_wf(forcast.get(i).element("night").element("type").getText());
//						fs.setF_n_4_wf_img();
			}else if(i==4){
				fs.setF_day_5((int)reGexNum(forcast.get(i).element("date").getText()));
				fs.setF_week_5(getWeek(forcast.get(i).element("date").getText()));
				fs.setF_temp_h5(reGexNum(forcast.get(i).element("high").getText()));
				fs.setF_temp_l5(reGexNum(forcast.get(i).element("low").getText()));
				
				fs.setF_d_5_fl(reGexNum(forcast.get(i).element("day").element("fengli").getText())+"");
				fs.setF_d_5_fx(forcast.get(i).element("day").element("fengxiang").getText());
				fs.setF_d_5_wf(forcast.get(i).element("day").element("type").getText());
//						fs.setF_d_5_wf_img();
//						
				fs.setF_n_5_fl(reGexNum(forcast.get(i).element("night").element("fengli").getText())+"");
				fs.setF_n_5_fx(forcast.get(i).element("night").element("fengxiang").getText());
				fs.setF_n_5_wf(forcast.get(i).element("night").element("type").getText());
//						fs.setF_n_5_wf_img();
			}
			
		}
		 ad.setForcast(fs);
//		System.out.println(fs.toString());
	}

	private void readReal(String cityid,String county,AllData ad, Real real, Element node) {
		//解析实况
		real.setCity(node.element("city").getText());
		real.setUpdatetime(node.element("updatetime").getText()+":00");
		real.setR_fl(reGexNum(node.element("fengli").getText()));
		real.setR_fx(node.element("fengxiang").getText());
		real.setSunrise_1(node.element("sunrise_1").getText()+":00");
		real.setSunset_1(node.element("sunset_1").getText()+":00");
		real.setR_hum(reGexNum(node.element("shidu").getText()));
		real.setR_temp(Double.parseDouble(node.element("wendu").getText().toString()));
		
		real.setCounty(county);
		real.setCounty_id(cityid);
		
		ad.setReal(real);
		
//		System.out.println(real.toString());
	}
	
	public static void main(String[] args) {
		try {
//			RealForcastLifeWarnFromChinaWeather.saveWF2DbBatch(" in('北京','海淀','朝阳') ");
			RealForcastLifeWarnFromChinaWeather.saveWF2DbBatch( " city_name  not in('') ");
//			RealForcastLifeWarnFromChinaWeather.saveWF2DbBatch(" province_name   in('甘肃') ");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// WeatherRealForcastLifeWarning.save2db(" not in('北京','海淀','朝阳') ");
	}
	
	public static  double reGexNum(String str){
	        /**
	         * 提取金额,规则为只提取数字和点号,必须有点号
	         * 格式可以为0.0或者，11
	         * @param cost
	         * @return
	         */
	            Pattern compile = Pattern.compile("(\\d+\\.\\d+)|(\\d+)");
	            Matcher matcher = compile.matcher(str);
	            //System.out.println( matcher.group());
	            if(matcher.find()){
	            	 return Double.valueOf(matcher.group());	
	            }
	            return 0;
	}
	
	public static String getWeek(String d){
		return d.substring(d.length()-1).toString();
	}
	
	public static void saveWF2DbBatch(String notInSQL) throws SQLException{
		//获取数据库参数
		final List<Map<String, Object>> list=getCityFromDb(notInSQL);
		//获取网络数据并解析
		List<AllData> all=null;
		   int size=50;
			int j=list.size()%size;
			if(j!=0){
				j=list.size()/size+1;
			}else{
				j=list.size()/size;
			}
//			System.err.println((list.size()/size)+"共分"+j+"次执行");
			for (int i = 0; i < j; i++) {
				all=new ArrayList<>();
			   for (int k = i*size; k < (i*size)+size; k++) {
//				   System.out.println(i);
				   if(i==j-1&&k==list.size()) break;
				   all.add(new RealForcastLifeWarnFromChinaWeather().getAllData(list.get(k).get("county_weather").toString(),list.get(k).get("county_name").toString()));
			    }
			   QueryRunBatch(all);
//			   System.out.println("第"+i);
			}
		
		
	}

	private static void QueryRunBatch(final List<AllData> all) {
		StringBuilder sb=new StringBuilder();
		Object[][] params=new Object[all.size()][245];
		sb.append("INSERT INTO   d_weather_real_forcast_life_warning ")
		  .append("( city,county,county_id,updatetime,r_fx,sunrise_1,sunset_1,r_temp,")
		  .append("r_hum,r_fx_img,r_fl,")
		  .append("f_week_1,f_d_1_wf,f_d_1_fx,f_d_1_fl,f_n_1_wf,")
		  .append("f_n_1_fx,f_n_1_fl,f_temp_h1,f_temp_l1,f_day_1,f_d_1_wf_img,f_d_1_fx_img,")
		  .append("f_n_1_wf_img,f_n_1_fx_img,f_week_2,f_d_2_wf,f_d_2_fx,f_d_2_fl,f_n_2_wf,")
		  .append("f_n_2_fx,f_n_2_fl,f_temp_h2,f_temp_l2,f_day_2,f_d_2_wf_img,f_d_2_fx_img,")
		  .append("f_n_2_wf_img,f_n_2_fx_img,f_week_3,f_d_3_wf,f_d_3_fx,f_d_3_fl,f_n_3_wf,")
		  .append("f_n_3_fx,f_n_3_fl,f_temp_h3,f_temp_l3,f_day_3,f_d_3_wf_img,f_d_3_fx_img,")
		  .append("f_n_3_wf_img,f_n_3_fx_img,f_week_4,f_d_4_wf,f_d_4_fx,f_d_4_fl,f_n_4_wf,")
		  .append("f_n_4_fx,f_n_4_fl,f_temp_h4,f_temp_l4,f_day_4,f_d_4_wf_img,f_d_4_fx_img,")
		  .append("f_n_4_wf_img,f_n_4_fx_img,f_week_5,f_d_5_wf,f_d_5_fx,f_d_5_fl,f_n_5_wf,")
		  .append("f_n_5_fx,f_n_5_fl,f_temp_h5,f_temp_l5,f_day_5,f_d_5_wf_img,f_d_5_fx_img,")
		  .append("f_n_5_wf_img,f_n_5_fx_img,")
		  .append("w_form,w_type,w_type_img,w_degree,w_degree_img,")
		  .append("w_title,w_details,w_standard,w_suggest,w_time,")
		  .append("l_name_cl,l_value_cl,l_detail_cl,")
		  .append("l_name_ssd,l_value_ssd,l_detail_ssd,l_name_cy,l_value_cy,l_detail_cy,l_name_gm,")
		  .append("l_value_gm,l_detail_gm,l_name_ls,l_value_ls,l_detail_ls,l_name_ly,l_value_ly,l_detail_ly,")
		  .append("l_name_zwx,l_value_zwx,l_detail_zwx,l_name_xc,l_value_xc,l_detail_xc,l_name_yd,l_value_yd,")
		  .append("l_detail_yd,l_name_yh,l_value_yh,l_detail_yh,l_name_ys,l_value_ys,l_detail_ys ")
		  .append(",creat_time)")
		 .append("VALUES  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,now()) ")
		
		 .append(" ON DUPLICATE KEY UPDATE   ")
		  .append("updatetime=?,r_fx=?,sunrise_1=?,sunset_1=?,r_temp=?,")
		  .append("r_hum=?,r_fx_img=?,r_fl=?,")
		  .append("f_week_1=?,f_d_1_wf=?,f_d_1_fx=?,f_d_1_fl=?,f_n_1_wf=?,")
		  .append("f_n_1_fx=?,f_n_1_fl=?,f_temp_h1=?,f_temp_l1=?,f_day_1=?,f_d_1_wf_img=?,f_d_1_fx_img=?,")
		  .append("f_n_1_wf_img=?,f_n_1_fx_img=?,f_week_2=?,f_d_2_wf=?,f_d_2_fx=?,f_d_2_fl=?,f_n_2_wf=?,")
		  .append("f_n_2_fx=?,f_n_2_fl=?,f_temp_h2=?,f_temp_l2=?,f_day_2=?,f_d_2_wf_img=?,f_d_2_fx_img=?,")
		  .append("f_n_2_wf_img=?,f_n_2_fx_img=?,f_week_3=?,f_d_3_wf=?,f_d_3_fx=?,f_d_3_fl=?,f_n_3_wf=?,")
		  .append("f_n_3_fx=?,f_n_3_fl=?,f_temp_h3=?,f_temp_l3=?,f_day_3=?,f_d_3_wf_img=?,f_d_3_fx_img=?,")
		  .append("f_n_3_wf_img=?,f_n_3_fx_img=?,f_week_4=?,f_d_4_wf=?,f_d_4_fx=?,f_d_4_fl=?,f_n_4_wf=?,")
		  .append("f_n_4_fx=?,f_n_4_fl=?,f_temp_h4=?,f_temp_l4=?,f_day_4=?,f_d_4_wf_img=?,f_d_4_fx_img=?,")
		  .append("f_n_4_wf_img=?,f_n_4_fx_img=?,f_week_5=?,f_d_5_wf=?,f_d_5_fx=?,f_d_5_fl=?,f_n_5_wf=?,")
		  .append("f_n_5_fx=?,f_n_5_fl=?,f_temp_h5=?,f_temp_l5=?,f_day_5=?,f_d_5_wf_img=?,f_d_5_fx_img=?,")
		  .append("f_n_5_wf_img=?,f_n_5_fx_img=?,")
		  .append("w_form=?,w_type=?,w_type_img=?,w_degree=?,w_degree_img=?,")
		  .append("w_title=?,w_details=?,w_standard=?,w_suggest=?,w_time=?,")
		  .append("l_name_cl=?,l_value_cl=?,l_detail_cl=?,")
		  .append("l_name_ssd=?,l_value_ssd=?,l_detail_ssd=?,l_name_cy=?,l_value_cy=?,l_detail_cy=?,l_name_gm=?,")
		  .append("l_value_gm=?,l_detail_gm=?,l_name_ls=?,l_value_ls=?,l_detail_ls=?,l_name_ly=?,l_value_ly=?,l_detail_ly=?,")
		  .append("l_name_zwx=?,l_value_zwx=?,l_detail_zwx=?,l_name_xc=?,l_value_xc=?,l_detail_xc=?,l_name_yd=?,l_value_yd=?,")
		  .append("l_detail_yd=?,l_name_yh=?,l_value_yh=?,l_detail_yh=?,l_name_ys=?,l_value_ys=?,l_detail_ys ")
		  .append("=?,creat_time=now()");//批量
		try {
			 AllData ai;
			for (int i = 0; i < all.size(); i++) {
				 ai = all.get(i);
				//实况
				 params[i][0]= ai.getReal().getCity()==null?"":ai.getReal().getCity();
				 params[i][1]=  ai.getReal().getCounty();
				 params[i][2]=  ai.getReal().getCounty_id();
				 params[i][3]=  ai.getReal().getUpdatetime();
				 params[i][4]=  ai.getReal().getR_fx();
				 params[i][5]=  ai.getReal().getSunrise_1();
				 params[i][6]=  ai.getReal().getSunset_1();
				 params[i][7]=  ai.getReal().getR_temp();
				 params[i][8]=  ai.getReal().getR_hum();
				 params[i][9]=  ai.getReal().getR_fx_img();
				 params[i][10]=  ai.getReal().getR_fl();
				//预报第一天
				 params[i][11]=  ai.getForcast().getF_week_1();
				 params[i][12]=  ai.getForcast().getF_d_1_wf();
				 params[i][13]=  ai.getForcast().getF_d_1_fx();
				 params[i][14]=  ai.getForcast().getF_d_1_fl();
				 params[i][15]=  ai.getForcast().getF_n_1_wf();
				 params[i][16]=  ai.getForcast().getF_n_1_fx();
				 params[i][17]=  ai.getForcast().getF_n_1_fl();
				 params[i][18]=  ai.getForcast().getF_temp_h1();
				 params[i][19]=  ai.getForcast().getF_temp_l1();
				 params[i][20]=  ai.getForcast().getF_day_1();
				 params[i][21]=  ai.getForcast().getF_d_1_wf_img();
				 params[i][22]=  ai.getForcast().getF_d_1_fx_img();
				 params[i][23]=  ai.getForcast().getF_n_1_wf_img();
				 params[i][24]=  ai.getForcast().getF_n_1_fx_img();
				//预报第二天
				 params[i][25]= ai.getForcast().getF_week_2();
				 params[i][26]= ai.getForcast().getF_d_2_wf();
				 params[i][27]= ai.getForcast().getF_d_2_fx();
				 params[i][28]= ai.getForcast().getF_d_2_fl();
				 params[i][29]= ai.getForcast().getF_n_2_wf();
				 params[i][30]= ai.getForcast().getF_n_2_fx();
				 params[i][31]= ai.getForcast().getF_n_2_fl();
				 params[i][32]= ai.getForcast().getF_temp_h2();
				 params[i][33]= ai.getForcast().getF_temp_l2();
				 params[i][34]= ai.getForcast().getF_day_2();
				 params[i][35]= ai.getForcast().getF_d_2_wf_img();
				 params[i][36]= ai.getForcast().getF_d_2_fx_img();
				 params[i][37]= ai.getForcast().getF_n_2_wf_img();
				 params[i][38]= ai.getForcast().getF_n_2_fx_img();
				//预报第三天
				 params[i][39]= ai.getForcast().getF_week_3();
				 params[i][40]= ai.getForcast().getF_d_3_wf();
				 params[i][41]= ai.getForcast().getF_d_3_fx();
				 params[i][42]= ai.getForcast().getF_d_3_fl();
				 params[i][43]= ai.getForcast().getF_n_3_wf();
				 params[i][44]= ai.getForcast().getF_n_3_fx();
				 params[i][45]= ai.getForcast().getF_n_3_fl();
				 params[i][46]= ai.getForcast().getF_temp_h3();
				 params[i][47]= ai.getForcast().getF_temp_l3();
				 params[i][48]= ai.getForcast().getF_day_3();
				 params[i][49]= ai.getForcast().getF_d_3_wf_img();
				 params[i][50]= ai.getForcast().getF_d_3_fx_img();
				 params[i][51]= ai.getForcast().getF_n_3_wf_img();
				 params[i][52]= ai.getForcast().getF_n_3_fx_img();
				
				//预报第四天
				 params[i][53]= ai.getForcast().getF_week_4();
				 params[i][54]= ai.getForcast().getF_d_4_wf();
				 params[i][55]= ai.getForcast().getF_d_4_fx();
				 params[i][56]= ai.getForcast().getF_d_4_fl();
				 params[i][57]= ai.getForcast().getF_n_4_wf();
				 params[i][58]= ai.getForcast().getF_n_4_fx();
				 params[i][59]= ai.getForcast().getF_n_4_fl();
				 params[i][60]= ai.getForcast().getF_temp_h4();
				 params[i][61]= ai.getForcast().getF_temp_l4();
				 params[i][62]= ai.getForcast().getF_day_4();
				 params[i][63]= ai.getForcast().getF_d_4_wf_img();
				 params[i][64]= ai.getForcast().getF_d_4_fx_img();
				 params[i][65]= ai.getForcast().getF_n_4_wf_img();
				 params[i][66]= ai.getForcast().getF_n_4_fx_img();
				//预报第五天
				 params[i][67]= ai.getForcast().getF_week_5();
				 params[i][68]= ai.getForcast().getF_d_5_wf();
				 params[i][69]= ai.getForcast().getF_d_5_fx();
				 params[i][70]= ai.getForcast().getF_d_5_fl();
				 params[i][71]= ai.getForcast().getF_n_5_wf();
				 params[i][72]= ai.getForcast().getF_n_5_fx();
				 params[i][73]= ai.getForcast().getF_n_5_fl();
				 params[i][74]= ai.getForcast().getF_temp_h5();
				 params[i][75]= ai.getForcast().getF_temp_l5();
				 params[i][76]= ai.getForcast().getF_day_5();
				 params[i][77]= ai.getForcast().getF_d_5_wf_img();
				 params[i][78]= ai.getForcast().getF_d_5_fx_img();
				 params[i][79]= ai.getForcast().getF_n_5_wf_img();
				 params[i][80]= ai.getForcast().getF_n_5_fx_img();
				
				//预警
				 params[i][81]= ai.getWarning().getW_form();
				 params[i][82]= ai.getWarning().getW_type();
				 params[i][83]= ai.getWarning().getW_type_img();
				 params[i][84]= ai.getWarning().getW_degree();
				 params[i][85]= ai.getWarning().getW_degree_img();
				 params[i][86]= ai.getWarning().getW_title();
				 params[i][87]= ai.getWarning().getW_details();
				 params[i][88]= ai.getWarning().getW_standard();
				 params[i][89]= ai.getWarning().getW_suggest();
				 params[i][90]= ai.getWarning().getW_time();
				
				//生活指数
				 params[i][91]= ai.getLf().getL_name_cl();
				 params[i][92]= ai.getLf().getL_value_cl();
				 params[i][93]= ai.getLf().getL_detail_cl();
				 params[i][94]= ai.getLf().getL_name_ssd();
				 params[i][95]= ai.getLf().getL_value_ssd();
				 params[i][96]= ai.getLf().getL_detail_ssd();
				 params[i][97]= ai.getLf().getL_name_cy();
				 params[i][98]= ai.getLf().getL_value_cy();
				 params[i][99]= ai.getLf().getL_detail_cy();
				 params[i][100]= ai.getLf().getL_name_gm();
				 params[i][101]= ai.getLf().getL_value_gm();
				 params[i][102]= ai.getLf().getL_detail_gm();
				 params[i][103]= ai.getLf().getL_name_ls();
				 params[i][104]= ai.getLf().getL_value_ls();
				 params[i][105]= ai.getLf().getL_detail_ls();
				 params[i][106]= ai.getLf().getL_name_ly();
				 params[i][107]= ai.getLf().getL_value_ly();
				 params[i][108]= ai.getLf().getL_detail_ly();
				 params[i][109]= ai.getLf().getL_name_zwx();
				 params[i][110]= ai.getLf().getL_value_zwx();
				 params[i][111]= ai.getLf().getL_detail_zwx();
				 params[i][112]= ai.getLf().getL_name_xc();
				 params[i][113]= ai.getLf().getL_value_xc();
				 params[i][114]= ai.getLf().getL_detail_xc();
				 params[i][115]= ai.getLf().getL_name_yd();
				 params[i][116]= ai.getLf().getL_value_yd();
				 params[i][117]= ai.getLf().getL_detail_yd();
				 params[i][118]= ai.getLf().getL_name_yh();
				 params[i][119]= ai.getLf().getL_value_yh();
				 params[i][120]= ai.getLf().getL_detail_yh();
				 params[i][121]= ai.getLf().getL_name_ys();
				 params[i][122]= ai.getLf().getL_value_ys();
				 params[i][123]= ai.getLf().getL_detail_ys();
				 
				 
				 
				 //更新
				 params[i][124]=  ai.getReal().getUpdatetime();
				 params[i][125]=  ai.getReal().getR_fx();
				 params[i][126]=  ai.getReal().getSunrise_1();
				 params[i][127]=  ai.getReal().getSunset_1();
				 params[i][128]=  ai.getReal().getR_temp();
				 params[i][129]=  ai.getReal().getR_hum();
				 params[i][130]=  ai.getReal().getR_fx_img();
				 params[i][131]=  ai.getReal().getR_fl();
				//预报第一天
				 params[i][132]=  ai.getForcast().getF_week_1();
				 params[i][133]=  ai.getForcast().getF_d_1_wf();
				 params[i][134]=  ai.getForcast().getF_d_1_fx();
				 params[i][135]=  ai.getForcast().getF_d_1_fl();
				 params[i][136]=  ai.getForcast().getF_n_1_wf();
				 params[i][137]=  ai.getForcast().getF_n_1_fx();
				 params[i][138]=  ai.getForcast().getF_n_1_fl();
				 params[i][139]=  ai.getForcast().getF_temp_h1();
				 params[i][140]=  ai.getForcast().getF_temp_l1();
				 params[i][141]=  ai.getForcast().getF_day_1();
				 params[i][142]=  ai.getForcast().getF_d_1_wf_img();
				 params[i][143]=  ai.getForcast().getF_d_1_fx_img();
				 params[i][144]=  ai.getForcast().getF_n_1_wf_img();
				 params[i][145]=  ai.getForcast().getF_n_1_fx_img();
				//预报第二天
				 params[i][146]= ai.getForcast().getF_week_2();
				 params[i][147]= ai.getForcast().getF_d_2_wf();
				 params[i][148]= ai.getForcast().getF_d_2_fx();
				 params[i][149]= ai.getForcast().getF_d_2_fl();
				 params[i][150]= ai.getForcast().getF_n_2_wf();
				 params[i][151]= ai.getForcast().getF_n_2_fx();
				 params[i][152]= ai.getForcast().getF_n_2_fl();
				 params[i][153]= ai.getForcast().getF_temp_h2();
				 params[i][154]= ai.getForcast().getF_temp_l2();
				 params[i][155]= ai.getForcast().getF_day_2();
				 params[i][156]= ai.getForcast().getF_d_2_wf_img();
				 params[i][157]= ai.getForcast().getF_d_2_fx_img();
				 params[i][158]= ai.getForcast().getF_n_2_wf_img();
				 params[i][159]= ai.getForcast().getF_n_2_fx_img();
				//预报第三天
				 params[i][160]= ai.getForcast().getF_week_3();
				 params[i][161]= ai.getForcast().getF_d_3_wf();
				 params[i][162]= ai.getForcast().getF_d_3_fx();
				 params[i][163]= ai.getForcast().getF_d_3_fl();
				 params[i][164]= ai.getForcast().getF_n_3_wf();
				 params[i][165]= ai.getForcast().getF_n_3_fx();
				 params[i][166]= ai.getForcast().getF_n_3_fl();
				 params[i][167]= ai.getForcast().getF_temp_h3();
				 params[i][168]= ai.getForcast().getF_temp_l3();
				 params[i][169]= ai.getForcast().getF_day_3();
				 params[i][170]= ai.getForcast().getF_d_3_wf_img();
				 params[i][171]= ai.getForcast().getF_d_3_fx_img();
				 params[i][172]= ai.getForcast().getF_n_3_wf_img();
				 params[i][173]= ai.getForcast().getF_n_3_fx_img();
				
				//预报第四天
				 params[i][174]= ai.getForcast().getF_week_4();
				 params[i][175]= ai.getForcast().getF_d_4_wf();
				 params[i][176]= ai.getForcast().getF_d_4_fx();
				 params[i][177]= ai.getForcast().getF_d_4_fl();
				 params[i][178]= ai.getForcast().getF_n_4_wf();
				 params[i][179]= ai.getForcast().getF_n_4_fx();
				 params[i][180]= ai.getForcast().getF_n_4_fl();
				 params[i][181]= ai.getForcast().getF_temp_h4();
				 params[i][182]= ai.getForcast().getF_temp_l4();
				 params[i][183]= ai.getForcast().getF_day_4();
				 params[i][184]= ai.getForcast().getF_d_4_wf_img();
				 params[i][185]= ai.getForcast().getF_d_4_fx_img();
				 params[i][186]= ai.getForcast().getF_n_4_wf_img();
				 params[i][187]= ai.getForcast().getF_n_4_fx_img();
				//预报第五天
				 params[i][188]= ai.getForcast().getF_week_5();
				 params[i][189]= ai.getForcast().getF_d_5_wf();
				 params[i][190]= ai.getForcast().getF_d_5_fx();
				 params[i][191]= ai.getForcast().getF_d_5_fl();
				 params[i][192]= ai.getForcast().getF_n_5_wf();
				 params[i][193]= ai.getForcast().getF_n_5_fx();
				 params[i][194]= ai.getForcast().getF_n_5_fl();
				 params[i][195]= ai.getForcast().getF_temp_h5();
				 params[i][196]= ai.getForcast().getF_temp_l5();
				 params[i][197]= ai.getForcast().getF_day_5();
				 params[i][198]= ai.getForcast().getF_d_5_wf_img();
				 params[i][199]= ai.getForcast().getF_d_5_fx_img();
				 params[i][200]= ai.getForcast().getF_n_5_wf_img();
				 params[i][201]= ai.getForcast().getF_n_5_fx_img();
				
				//预警
				 params[i][202]= ai.getWarning().getW_form();
				 params[i][203]= ai.getWarning().getW_type();
				 params[i][204]= ai.getWarning().getW_type_img();
				 params[i][205]= ai.getWarning().getW_degree();
				 params[i][206]= ai.getWarning().getW_degree_img();
				 params[i][207]= ai.getWarning().getW_title();
				 params[i][208]= ai.getWarning().getW_details();
				 params[i][209]= ai.getWarning().getW_standard();
				 params[i][210]= ai.getWarning().getW_suggest();
				 params[i][211]= ai.getWarning().getW_time();
				
				//生活指数
				 params[i][212]= ai.getLf().getL_name_cl();
				 params[i][213]= ai.getLf().getL_value_cl();
				 params[i][214]= ai.getLf().getL_detail_cl();
				 params[i][215]= ai.getLf().getL_name_ssd();
				 params[i][216]= ai.getLf().getL_value_ssd();
				 params[i][217]= ai.getLf().getL_detail_ssd();
				 params[i][218]= ai.getLf().getL_name_cy();
				 params[i][219]= ai.getLf().getL_value_cy();
				 params[i][220]= ai.getLf().getL_detail_cy();
				 params[i][221]= ai.getLf().getL_name_gm();
				 params[i][222]= ai.getLf().getL_value_gm();
				 params[i][223]= ai.getLf().getL_detail_gm();
				 params[i][224]= ai.getLf().getL_name_ls();
				 params[i][225]= ai.getLf().getL_value_ls();
				 params[i][226]= ai.getLf().getL_detail_ls();
				 params[i][227]= ai.getLf().getL_name_ly();
				 params[i][228]= ai.getLf().getL_value_ly();
				 params[i][229]= ai.getLf().getL_detail_ly();
				 params[i][230]= ai.getLf().getL_name_zwx();
				 params[i][231]= ai.getLf().getL_value_zwx();
				 params[i][232]= ai.getLf().getL_detail_zwx();
				 params[i][233]= ai.getLf().getL_name_xc();
				 params[i][234]= ai.getLf().getL_value_xc();
				 params[i][235]= ai.getLf().getL_detail_xc();
				 params[i][236]= ai.getLf().getL_name_yd();
				 params[i][237]= ai.getLf().getL_value_yd();
				 params[i][238]= ai.getLf().getL_detail_yd();
				 params[i][239]= ai.getLf().getL_name_yh();
				 params[i][240]= ai.getLf().getL_value_yh();
				 params[i][241]= ai.getLf().getL_detail_yh();
				 params[i][242]= ai.getLf().getL_name_ys();
				 params[i][243]= ai.getLf().getL_value_ys();
				 params[i][244]= ai.getLf().getL_detail_ys();
			}
			qr.batch(sb.toString(), params);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@SuppressWarnings("unchecked")
	private static List<Map<String, Object>>  getCityFromDb(String sqlInNotIn) throws SQLException{
   		 String sql = "select county_name ,county_weather from b_weaher_china_city where 1=1 and  "+sqlInNotIn;//批量
		return  qr.query(sql, new MapListHandler());
	}
}
